import util from '@/libs/util'
export default {
    namespaced: true,
    state: {
        // 注册信息
        username: '',
        // 用户信息
        info: {},
        token: util.cookies.get('token')
            // this.$store.state.d2admin.user.token
    },
    actions: {
        /**
         * @description 设置用户数据
         * @param {Object} context
         * @param {*} info info
         */
        async seti({ state, dispatch }, info) {
            // store 赋值
            console.log(info)
            state.info = info
            state.token = info.token
                // 持久化
            await dispatch('d2admin/db/set', {
                dbName: 'sys',
                path: 'user.info',
                value: info,
                user: true
            }, { root: true })
        },
        /**
         * @description 从数据库取用户数据
         * @param {Object} context
         */
        async load({ state, dispatch }) {
            // store 赋值
            state.info = await dispatch('d2admin/db/get', {
                dbName: 'sys',
                path: 'user.info',
                defaultValue: {},
                user: true
            }, { root: true })
        }
    }
}